/**
 * 
 */
package de.htwg.ppt2html5.util;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.docx4j.openpackaging.parts.PresentationML.SlidePart;


/**
 * util class for sorting Slide lists
 * 
 * @author Roman Allenov
 */
public class Sorting {

   /**
    * this method sorts the given slides list for later use.
    * 
    * @param slidePartsList
    */
   public static void sortList(List<SlidePart> slidePartsList)
   {
      // list to compare with partNames
      List<String> tmpList = new ArrayList<String>();
      // tmp list holding original SlideParts
      List<SlidePart> tmpParts = new ArrayList<SlidePart>();

      // copy originals
      Iterator<SlidePart> iter = slidePartsList.listIterator();
      while (iter.hasNext()) {
         tmpParts.add(iter.next());
      }
      // clear before re-adding
      slidePartsList.clear();

      int size = tmpParts.size();
      for (int i = 0; i < size; i++) {
         tmpList.add(tmpParts.get(i).getPartName().getName());
      }

      Collections.sort(tmpList);

      for (String partName : tmpList) {
         for (SlidePart tmpPart : tmpParts) {
            if (partName.equals(tmpPart.getPartName().getName())) {
               slidePartsList.add(tmpPart);
            }
         }
      }
   }
}
